from bzrc import BZRC, Command, ShootCommand
import sys, math, time, optparse, random, pprint


class Agent(object):

	def __init__(self, bzrc):
		self.bzrc = bzrc
		self.constants = self.bzrc.get_constants()
		self.commands = []
		self.state = []
		# Seconds since last state change
		self.lastStateChanged = []
		# Seconds since last shot
		self.lastShot = []
		# Desired turn angle
		self.desiredAngle = []
		# Desired position
		self.desiredPos = []

	def tick(self, time_diff):
		'''Some time has passed; decide what to do next'''

		# Reset my set of commands (we don't want to run old commands)
		self.commands = []

		# Decide what to do with each of my tanks
		for bot in mytanks:
			self.be_dumb(bot, time_diff)

		# Send the commands to the server
		results = self.bzrc.do_commands(self.commands)

	def be_dumb(self, bot, time_diff):
		command = Command(bot.index, 0, 0)
		self.commands.append(command)
		
def main():
	# Process CLI arguments.
	parser = optparse.OptionParser(usage = "%prog [options]",
								   version = "%prog 0.1")
	parser.add_option("-o", "--host", type="string",dest="host",
			metavar="HOST",default='localhost',
			help="hostname for the server")
	parser.add_option("-p", "--port", type="int",dest="port",
			metavar="PORT",default=3907,
			help="port number for the server")

	(options, args) = parser.parse_args()

	# Connect.
	#bzrc = BZRC(options.host, int(options.port), debug=True)
	bzrc = BZRC(options.host, int(options.port))

	agent = Agent(bzrc)

	prev_time = time.time()

	# Run the agent
	try:
		while True:
			time_diff = time.time() - prev_time
			agent.tick(time_diff)
			prev_time = time.time()
			time.sleep(.1)
	except KeyboardInterrupt:
		print "Exiting due to keyboard interrupt."
		bzrc.close()


if __name__ == '__main__':
	main()

# vim: et sw=4 sts=4
